#!/usr/bin/env python
#coding: utf-8
#-*- coding: utf-8 -*-

import os,re,sys,time

def getRoundNo():
    return time.strftime('%Y-%m-%d_%H_%S_%M',time.localtime(time.time()))

cmd = 'del /Q *.rar'
os.popen(cmd)

roundNo = getRoundNo()
logFileName = 'dl_' + roundNo +'.log'
cmd = 'wget -o ' + logFileName + ' http://feixin.10086.cn/download/pcclient/dodownload?id=61 '

startTime = time.strftime('%Y-%m-%d_%H_%S_%M',time.localtime(time.time()))
os.popen(cmd)
endTime = time.strftime('%Y-%m-%d_%H_%S_%M',time.localtime(time.time()))

pstr = r'(?<=\()[^(]+(?=\))'
#print pstr
p=re.compile( pstr )

logFile = open(logFileName, 'r')
logs = logFile.readlines()
logFile.close()

for i in range(-1,-20,-1):
    if  len(logs[i].strip()) > 0 :
        speedline = logs[i]
        print speedline
        break
    

resultFile = open('dl_speed.txt', 'a')
speed = ''
if logs:
    ret = p.findall(speedline)
    if ret:
        speed = ret[0]

    
# 下载速度写入文件
# resultFile.writelines('speed=' + speed + '&roundno=' + roundNo + '\n')
resultFile.writelines('\t' + 'download_test:\t' + startTime + '\t' + endTime + '\n')

resultFile.flush()

resultFile.close()



    
    

